package com.ml.mall.api.sys;

import com.ml.mall.annotation.LogMethodInvokeInformation;
import com.ml.mall.bean.base.ApiRestResult;
import com.ml.mall.bean.page.Page;
import com.ml.mall.bean.req.sys.SysSubRoutingDelDto;
import com.ml.mall.bean.req.sys.SysSubRoutingNewDto;
import com.ml.mall.bean.req.sys.SysSubRoutingQueryPageDto;
import com.ml.mall.consts.CommonConsts;
import com.ml.mall.consts.PermissionConst;
import com.ml.mall.entity.sys.SysRouting;
import com.ml.mall.entity.sys.SysSubscription;
import com.ml.mall.enums.CommonEnum;
import com.ml.mall.exception.BizException;
import com.ml.mall.service.sys.SysSubscriptionRoutingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @description 配套路由关系管理api
 * @author yx
 * @date 2021/9/15
 * @version 1.0
*/
@Api(tags = "【auth】配套路由")
@RestController
@RequestMapping("/subscription_routing")
public class SysSubscriptionRoutingController {
    @Autowired
    private SysSubscriptionRoutingService subscriptionRoutingService;

    @ApiOperation("分页查询配套路由信息")
    @PostMapping("/query_page")
//    @RequiresPermissions(PermissionConst.SUBSCRIPTION_ROUTING_QUERY_PAGE)
    @LogMethodInvokeInformation("分页查询配套路由信息")
    public ApiRestResult subRoutingQueryPage(@RequestBody @Valid SysSubRoutingQueryPageDto dto){
        Page<SysRouting> result = subscriptionRoutingService.subRoutingQueryPage(dto);
        if(null == result){
            throw new BizException(CommonEnum.SELECT_ERROR);
        }
        return ApiRestResult.ok(result);
    }

//    @ApiOperation("添加配套路由信息")
//    @PostMapping("/new")
////    @RequiresPermissions(PermissionConst.SUBSCRIPTION_ROUTING_NEW)
//    public ApiRestResult subRoutingNew(@RequestBody @Valid SysSubRoutingNewDto dto){
//        Integer result = subscriptionRoutingService.subRoutingNew(dto);
//        if(CommonConsts.FIXED_NUM_ZERO.equals(result)){
//            throw new BizException(CommonEnum.INSERT_ERROR);
//        }
//
//        return ApiRestResult.ok(result);
//    }
//
//    @ApiOperation("删除配套路由信息")
//    @PostMapping("/del")
////    @RequiresPermissions(PermissionConst.SUBSCRIPTION_ROUTING_DEL)
//    public ApiRestResult subRoutingDel(@RequestBody @Valid SysSubRoutingDelDto dto){
//        Integer result = subscriptionRoutingService.subRoutingDel(dto);
//        if(CommonConsts.FIXED_NUM_ZERO.equals(result)){
//            throw new BizException(CommonEnum.DELETE_ERROR);
//        }
//
//        return ApiRestResult.ok(result);
//    }
}
